package algotithm.interview.meituan.test1;

import java.io.*;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/20-16:01
 * 55%！
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String s1 = reader.readLine().replaceAll(" ","");
        String s2 = reader.readLine();
        int n = s2.length();
        StringBuilder sb = new StringBuilder();;
        for (int i = 0; i < n; i++) {
            sb.append(s1);
        }
        String s3 = sb.toString().replaceAll(" ","");
        int cnt = 0;
        int i = 0, j = 0;
        while (i < s3.length() && j < n) {
            while (s3.charAt(i) != s2.charAt(j)) {
                cnt++;
                i++;
            }
            if (s3.charAt(i) == s2.charAt(j)) {
                i++;
                j++;
            }
        }
        writer.write(cnt + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}
